/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.user.dao;

import com.nus.dataaccess.dao.base.dao.BaseDao;
import com.nus.dataaccess.dao.user.UserAccount;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author robin.foe
 */
public class UserAccountDao extends BaseDao<UserAccount>{

    private static UserAccountDao instance;

    public static UserAccountDao getInstance() {
        if (null == instance) {
            instance = new UserAccountDao();
        }
        return instance;
    }
    private UserAccountDao(){}
    
    @Override
    protected Class getReferenceClass() {return UserAccount.class;}

    public UserAccount getByUserName(String userName){
       Criteria crit = super.createCriteria();
       crit.add(Restrictions.eq("username", userName));
       crit.setMaxResults(1);
       List<UserAccount> userAccounts = crit.list();
       return (userAccounts!=null && !userAccounts.isEmpty()) ? userAccounts.get(0) : null;
    }

}
